﻿@page
@model IndexModel
@{
    ViewData["Title"] = "数据共享";
}


<div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
        <div id="filesroot" class="demo-tree"></div>

    </div>
</div>

<div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 15px;">
        <div id="excelContent" class="text-center" style="overflow-x:visible;overflow-y:visible;">

        </div>
    </div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
@section Scripts
{
    <script>
        function ShowExcel(data) {
            $.ajax({
                type: "POST",
                url: "Index?handler=OpenExcel&dir=" + encodeURIComponent(data.href),
                dataType: "html",
                //data: JSON.stringify({ dir: data.href }),
                //contentType: "application/json"
            }).done(function (htmlString) {
                //alert(htmlString)
                $("#excelContent").html(htmlString);
            });
        }

        $(document).ready(function () {
            $.ajax({
                type: "POST",
                url: "Index?handler=Send",
                contentType: "application/json"
            }).done(function (response) {
                layui.use(['tree', 'util'], function () {
                    var tree = layui.tree
                        , layer = layui.layer
                        //模拟数据1
                        , data = JSON.parse(response);

                    //仅节点左侧图标控制收缩
                    tree.render({
                        elem: '#filesroot'
                        , data: data
                        , onlyIconControl: true  //是否仅允许节点左侧图标控制展开收缩
                        , click: function (obj) {
                            if (obj && obj.data && obj.data.children === null) {
                                ShowExcel(obj.data)
                            }
                        }
                        , showLine: true  //是否开启连接线
                        , accordion: true
                        , onlyIconControl: false
                        , isJump: false
                    });
                });
                //layui.tree({ elem: '#filesroot', nodes: JSON.parse(response) });
            });
        });
    </script>
}